import msgControl from "./msgControl";
import PjControl from "./PjControl";

const { ccclass, property } = cc._decorator;

class Message {
	name: string
	content: string
	face: string
	mouth: string

	constructor(name: string, content: string, face: string, mouth: string) {
		this.name = name
		this.content = content
		this.face = face
		this.mouth = mouth
	}
}

@ccclass
export default class bgControl extends cc.Component {

	@property(PjControl)
	pjControl: PjControl = null
	@property(msgControl)
	msgControl: msgControl = null

	// onLoad () {}

	// 消息数组
	msgs: Message[] = null
	// 消息索引
	index: number = 0

	start() {
		this.msgs = [
			new Message("炮姐", "天气好好哦", "paojieface_02", "paojiemouth_02"),
			new Message("炮姐", "听说你这几天很忙", "paojieface_01", "paojiemouth_02"),
			new Message("炮姐", "又变猥琐了", "paojieface_01", "paojiemouth_01"),
			new Message("炮姐", "请我喝汽水吧", "paojieface_02", "paojiemouth_01")
		]
		// 鼠标点击对话
		this.node.on(cc.Node.EventType.MOUSE_DOWN, (event) => {
			if (this.index < this.msgs.length) {
				// 如果对话面板没显示
				if (this.msgControl.node.active == false) {
					this.msgControl.node.active = true
				}
				// 读取消息
				let msg = this.msgs[this.index++]
				// 显示消息
				this.pjControl.setImage(msg.face, msg.mouth)
				this.msgControl.setMessage(msg.name, msg.content)
			}
		})

	}

	// update (dt) {}
}
